package com.fyt.ZhongYaoApp.Controller;

import com.fyt.ZhongYaoApp.pojo.Doctor;
import com.fyt.ZhongYaoApp.pojo.DoctorCat;
import com.fyt.ZhongYaoApp.pojo.pg.DoctorCatPG;
import com.fyt.ZhongYaoApp.pojo.pg.DoctorPG;
import com.fyt.ZhongYaoApp.pojo.dto.PageDTO;
import com.fyt.ZhongYaoApp.pojo.vo.DoctorByCatVO;
import com.fyt.ZhongYaoApp.pojo.vo.DoctorQueery;
import com.fyt.ZhongYaoApp.pojo.PageBean;
import com.fyt.ZhongYaoApp.pojo.Result;
import com.fyt.ZhongYaoApp.service.DoctorService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/doctor")
@Tag(name = "doctor",description = "the doctor API") // 接口大标题
public class DoctorController {

    @Autowired
    private DoctorService doctorService;

    @PostMapping("/add")
    public Result addDoctor(@RequestBody Doctor doctor) {
        doctorService.add(doctor);
        return Result.success("医生添加成功");
    }

    @GetMapping("/list")
    public Result<PageBean<DoctorQueery>> doctorList(@RequestBody PageDTO pageDTO) {

        PageBean<DoctorQueery> list = doctorService.doctorList(pageDTO.getPageNum(), pageDTO.getPageSize());
        return Result.success(list);
    }

    /**
     * 根据种类查询医生列表
     * @return
     */
    @GetMapping("doctorListByCat")
    public Result<PageBean<DoctorByCatVO>> doctorListByCat(@RequestBody DoctorCatPG doctorCatPG) {

        DoctorCat doctorCat = new DoctorCat();
        BeanUtils.copyProperties(doctorCatPG, doctorCat);// 数据拷贝
        PageBean<DoctorByCatVO> list = doctorService.doctorListByCat(doctorCat,doctorCatPG.getPageNum(),doctorCatPG.getPageSize());
        return Result.success(list);
    }

    /**
     * 模糊查询医生信息
     * @param doctorPG
     * @return
     */
    @GetMapping("doctorListByName")
    public Result<PageBean<DoctorByCatVO>> doctorListByName(@RequestBody DoctorPG doctorPG) {

        PageBean<DoctorByCatVO> list = doctorService.doctorListByName(doctorPG.getHospitalId(), doctorPG.getPageNum(), doctorPG.getPageSize());
        return Result.success(list);
    }

    /**
     * 查询医生详情
     * @return
     */
    @GetMapping("doctorintroduction")
    public Result<PageBean<DoctorQueery>> doctorintroduction(@RequestBody DoctorPG doctorPG) {

        Doctor doctor = new Doctor();
        BeanUtils.copyProperties(doctorPG, doctor);// 数据拷贝
        PageBean<DoctorQueery> list = doctorService.doctorIntroduction(doctor, doctorPG.getPageNum(), doctorPG.getPageSize());
        return Result.success(list);
    }

}
